package OrderService

import (
	"context"
	"gdshop-font-api-go/app/request/OrderReq"
	"gdshop-font-api-go/app/service/OrderBaseService"
	"gdshop-font-api-go/library/response"
	"github.com/gogf/gf/frame/g"
)

func List(ctx context.Context, parames *OrderReq.List) *response.JsonResponse {
	/*countDb := toolsDb.GetUnSafaTableAddDeleteWhere(
		ctx,
		"order").Where(
		"delete_at<1 AND member_id=?",
		parames.MemberId,
	).Fields(
		"1")
	listDb := toolsDb.GetUnSafaTableAddDeleteWhere(ctx, "order").Page(
		parames.Page, parames.PageSize,
	).Order("id DESC").Where(
		"delete_at<1 AND member_id=?",
		parames.MemberId,
	)
	if parames.Status > 0 {
		if parames.Status == 3 {
			countDb.Where("status IN (?)", []int{2, 3})
			listDb.Where("status IN (?)", []int{2, 3})
		} else {
			countDb.Where("status=?", parames.Status)
			listDb.Where("status=?", parames.Status)
		}
	}
	var orderList []*OrderResp.Details
	count, countErr := countDb.Count()
	if countErr != nil {
		return response.FailByRequestMessage(nil, countErr.Error())
	}

	err := listDb.Structs(&orderList)

	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	} else {
		orderRespList := OrderResp.List{
			PageInfo:       tools.GetPageInfo(count, parames.Page, parames.PageSize),
			NextStatusText: GetNextStatusText(),
			StatusText:     GetStatusText(),
			PhotoBaseUrl:   g.Cfg().GetString("site.PhotoUrlProfix"),
		}
		if count > 0 {
			// 处理返回数据
			for _, item := range orderList {
				handleDetails(ctx, item)
			}

			orderRespList.List = orderList
		} else {
			orderRespList.List = []*OrderResp.Details{}
		}

		return response.SuccessByRequestMessageData(nil, "成功", orderRespList)
	}*/

	data, err := OrderBaseService.GetPager(ctx, g.Map{
		"delete_at<1 AND member_id=?": parames.MemberId,
	}, parames.Page, parames.PageSize, parames.Status, "")
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}

	return response.SuccessByRequestMessageData(nil, "成功", data)
}
